home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / aolcha1g / fun_with.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-09-05  |  17.8 KB  |  556 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Teco's ""Fun With Text"" Examples"
  4.    ClientHeight    =   6390
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   7665
  8.    LinkTopic       =   "Form1"
  9.    MaxButton       =   0   'False
  10.    ScaleHeight     =   6390
  11.    ScaleWidth      =   7665
  12.    StartUpPosition =   2  'CenterScreen
  13.    Begin VB.Frame Frame13 
  14.       Height          =   975
  15.       Left            =   0
  16.       TabIndex        =   41
  17.       Top             =   5400
  18.       Width           =   7575
  19.       Begin VB.Label Label15 
  20.          Alignment       =   2  'Center
  21.          BackStyle       =   0  'Transparent
  22.          Caption         =   "FOR ALL YOUR VB NEEDS:   http://www.planet-source-code.com/vb/"
  23.          BeginProperty Font 
  24.             Name            =   "MS Sans Serif"
  25.             Size            =   8.25
  26.             Charset         =   0
  27.             Weight          =   700
  28.             Underline       =   0   'False
  29.             Italic          =   0   'False
  30.             Strikethrough   =   0   'False
  31.          EndProperty
  32.          Height          =   255
  33.          Left            =   120
  34.          TabIndex        =   44
  35.          Top             =   720
  36.          Width           =   7335
  37.       End
  38.       Begin VB.Label Label14 
  39.          Alignment       =   2  'Center
  40.          Caption         =   "Special Thanks also goes out to ANTI for their Repetitions Counter Coding Example"
  41.          Height          =   255
  42.          Left            =   120
  43.          TabIndex        =   43
  44.          Top             =   480
  45.          Width           =   7335
  46.       End
  47.       Begin VB.Label Label13 
  48.          Alignment       =   2  'Center
  49.          Caption         =   "Special Thanks goes out to JASON MONROE for his Encrypt/Decrypt Coding Example."
  50.          Height          =   255
  51.          Left            =   120
  52.          TabIndex        =   42
  53.          Top             =   240
  54.          Width           =   7335
  55.       End
  56.    End
  57.    Begin VB.Frame Frame11 
  58.       Caption         =   "Example #6"
  59.       Height          =   1695
  60.       Left            =   3960
  61.       TabIndex        =   34
  62.       Top             =   3600
  63.       Width           =   3615
  64.       Begin VB.CommandButton Command11 
  65.          Caption         =   "Counter Letter ""E"""
  66.          Height          =   375
  67.          Left            =   1920
  68.          TabIndex        =   40
  69.          Top             =   1200
  70.          Width           =   1575
  71.       End
  72.       Begin VB.CommandButton Command10 
  73.          Caption         =   "Count Letter ""O"""
  74.          Height          =   375
  75.          Left            =   120
  76.          TabIndex        =   39
  77.          Top             =   1200
  78.          Width           =   1815
  79.       End
  80.       Begin VB.Frame Frame12 
  81.          Height          =   615
  82.          Left            =   120
  83.          TabIndex        =   36
  84.          Top             =   480
  85.          Width           =   3375
  86.          Begin VB.TextBox Text6 
  87.             Height          =   285
  88.             Left            =   720
  89.             TabIndex        =   38
  90.             Text            =   "Moo Is Definately For You Too"
  91.             Top             =   240
  92.             Width           =   2535
  93.          End
  94.          Begin VB.Label Label12 
  95.             Caption         =   "String:"
  96.             Height          =   255
  97.             Left            =   120
  98.             TabIndex        =   37
  99.             Top             =   240
  100.             Width           =   855
  101.          End
  102.       End
  103.       Begin VB.Label Label11 
  104.          Caption         =   "Repetitions                                    (
  105. 1999 Anti)"
  106.          Height          =   255
  107.          Left            =   120
  108.          TabIndex        =   35
  109.          Top             =   240
  110.          Width           =   3375
  111.       End
  112.    End
  113.    Begin VB.Frame Frame9 
  114.       Caption         =   "Example #5"
  115.       Height          =   1695
  116.       Left            =   0
  117.       TabIndex        =   27
  118.       Top             =   3600
  119.       Width           =   3855
  120.       Begin VB.CommandButton Command9 
  121.          Caption         =   "Encrypt"
  122.          Height          =   375
  123.          Left            =   2040
  124.          TabIndex        =   33
  125.          Top             =   1200
  126.          Width           =   1695
  127.       End
  128.       Begin VB.CommandButton Command8 
  129.          Caption         =   "Decrypt"
  130.          Height          =   375
  131.          Left            =   120
  132.          TabIndex        =   32
  133.          Top             =   1200
  134.          Width           =   1935
  135.       End
  136.       Begin VB.Frame Frame10 
  137.          Height          =   615
  138.          Left            =   120
  139.          TabIndex        =   29
  140.          Top             =   480
  141.          Width           =   3615
  142.          Begin VB.TextBox Text5 
  143.             Height          =   285
  144.             Left            =   720
  145.             TabIndex        =   31
  146.             Text            =   "Technical Communications"
  147.             Top             =   240
  148.             Width           =   2775
  149.          End
  150.          Begin VB.Label Label10 
  151.             Caption         =   "String:"
  152.             Height          =   255
  153.             Left            =   120
  154.             TabIndex        =   30
  155.             Top             =   240
  156.             Width           =   855
  157.          End
  158.       End
  159.       Begin VB.Label Label9 
  160.          Caption         =   "Data Encryption                  (
  161. 1999 Jason Monroe)"
  162.          Height          =   255
  163.          Left            =   120
  164.          TabIndex        =   28
  165.          Top             =   240
  166.          Width           =   3615
  167.       End
  168.    End
  169.    Begin VB.Frame Frame7 
  170.       Caption         =   "Example #4"
  171.       Height          =   1695
  172.       Left            =   3960
  173.       TabIndex        =   20
  174.       Top             =   1800
  175.       Width           =   3615
  176.       Begin VB.CommandButton Command7 
  177.          Caption         =   "Trim Trailing"
  178.          Height          =   375
  179.          Left            =   1920
  180.          TabIndex        =   26
  181.          Top             =   1200
  182.          Width           =   1575
  183.       End
  184.       Begin VB.CommandButton Command6 
  185.          Caption         =   "Trim Leading"
  186.          Height          =   375
  187.          Left            =   120
  188.          TabIndex        =   25
  189.          Top             =   1200
  190.          Width           =   1815
  191.       End
  192.       Begin VB.Frame Frame8 
  193.          Height          =   615
  194.          Left            =   120
  195.          TabIndex        =   22
  196.          Top             =   480
  197.          Width           =   3375
  198.          Begin VB.TextBox Text4 
  199.             Height          =   285
  200.             Left            =   720
  201.             TabIndex        =   24
  202.             Text            =   "     My The Sky Is Blue To You?   "
  203.             Top             =   240
  204.             Width           =   2535
  205.          End
  206.          Begin VB.Label Label8 
  207.             Caption         =   "String:"
  208.             Height          =   255
  209.             Left            =   120
  210.             TabIndex        =   23
  211.             Top             =   240
  212.             Width           =   735
  213.          End
  214.       End
  215.       Begin VB.Label Label7 
  216.          Caption         =   "Removing Trailing and Leading Spaces"
  217.          Height          =   255
  218.          Left            =   120
  219.          TabIndex        =   21
  220.          Top             =   240
  221.          Width           =   3255
  222.       End
  223.    End
  224.    Begin VB.Frame Frame5 
  225.       Caption         =   "Example #3"
  226.       Height          =   1695
  227.       Left            =   0
  228.       TabIndex        =   14
  229.       Top             =   1800
  230.       Width           =   3855
  231.       Begin VB.CommandButton Command5 
  232.          Caption         =   "Reverse String"
  233.          Height          =   375
  234.          Left            =   120
  235.          TabIndex        =   19
  236.          Top             =   1200
  237.          Width           =   3615
  238.       End
  239.       Begin VB.Frame Frame6 
  240.          Height          =   615
  241.          Left            =   120
  242.          TabIndex        =   16
  243.          Top             =   480
  244.          Width           =   3615
  245.          Begin VB.TextBox Text3 
  246.             Height          =   285
  247.             Left            =   720
  248.             TabIndex        =   18
  249.             Text            =   "Hippy Cowboys From Hell"
  250.             Top             =   240
  251.             Width           =   2775
  252.          End
  253.          Begin VB.Label Label6 
  254.             Caption         =   "String:"
  255.             Height          =   255
  256.             Left            =   120
  257.             TabIndex        =   17
  258.             Top             =   240
  259.             Width           =   615
  260.          End
  261.       End
  262.       Begin VB.Label Label5 
  263.          Caption         =   "Reversing Strings"
  264.          Height          =   255
  265.          Left            =   120
  266.          TabIndex        =   15
  267.          Top             =   240
  268.          Width           =   2655
  269.       End
  270.    End
  271.    Begin VB.Frame Frame3 
  272.       Caption         =   "Example #2"
  273.       Height          =   1695
  274.       Left            =   3960
  275.       TabIndex        =   7
  276.       Top             =   0
  277.       Width           =   3615
  278.       Begin VB.CommandButton Command4 
  279.          Caption         =   "lowercase"
  280.          Height          =   375
  281.          Left            =   1920
  282.          TabIndex        =   13
  283.          Top             =   1200
  284.          Width           =   1575
  285.       End
  286.       Begin VB.CommandButton Command3 
  287.          Caption         =   "UPPERCASE"
  288.          Height          =   375
  289.          Left            =   240
  290.          TabIndex        =   12
  291.          Top             =   1200
  292.          Width           =   1695
  293.       End
  294.       Begin VB.Frame Frame4 
  295.          Height          =   615
  296.          Left            =   120
  297.          TabIndex        =   9
  298.          Top             =   480
  299.          Width           =   3375
  300.          Begin VB.TextBox Text2 
  301.             Height          =   285
  302.             Left            =   720
  303.             TabIndex        =   11
  304.             Text            =   "Marmalade Milkmaid"
  305.             Top             =   240
  306.             Width           =   2535
  307.          End
  308.          Begin VB.Label Label4 
  309.             Caption         =   "String:"
  310.             Height          =   255
  311.             Left            =   120
  312.             TabIndex        =   10
  313.             Top             =   240
  314.             Width           =   735
  315.          End
  316.       End
  317.       Begin VB.Label Label3 
  318.          Caption         =   "Uppercase and Lowercase"
  319.          Height          =   255
  320.          Left            =   120
  321.          TabIndex        =   8
  322.          Top             =   240
  323.          Width           =   3135
  324.       End
  325.    End
  326.    Begin VB.Frame Frame1 
  327.       Caption         =   "Example #1"
  328.       Height          =   1695
  329.       Left            =   0
  330.       TabIndex        =   0
  331.       Top             =   0
  332.       Width           =   3855
  333.       Begin VB.CommandButton Command2 
  334.          Caption         =   "Replace ""A"" To ""B"""
  335.          Height          =   375
  336.          Left            =   2040
  337.          TabIndex        =   6
  338.          Top             =   1200
  339.          Width           =   1695
  340.       End
  341.       Begin VB.CommandButton Command1 
  342.          Caption         =   "Replace Spaces To ""+"""
  343.          Height          =   375
  344.          Left            =   120
  345.          TabIndex        =   5
  346.          Top             =   1200
  347.          Width           =   1935
  348.       End
  349.       Begin VB.Frame Frame2 
  350.          Height          =   615
  351.          Left            =   120
  352.          TabIndex        =   2
  353.          Top             =   480
  354.          Width           =   3615
  355.          Begin VB.TextBox Text1 
  356.             Height          =   285
  357.             Left            =   720
  358.             TabIndex        =   4
  359.             Text            =   "Ernie Earnsteain And I"
  360.             Top             =   240
  361.             Width           =   2775
  362.          End
  363.          Begin VB.Label Label2 
  364.             Caption         =   "String:"
  365.             Height          =   255
  366.             Left            =   120
  367.             TabIndex        =   3
  368.             Top             =   240
  369.             Width           =   855
  370.          End
  371.       End
  372.       Begin VB.Label Label1 
  373.          Caption         =   "Replacing Characters"
  374.          Height          =   255
  375.          Left            =   120
  376.          TabIndex        =   1
  377.          Top             =   240
  378.          Width           =   3615
  379.       End
  380.    End
  381. Attribute VB_Name = "Form1"
  382. Attribute VB_GlobalNameSpace = False
  383. Attribute VB_Creatable = False
  384. Attribute VB_PredeclaredId = True
  385. Attribute VB_Exposed = False
  386. Private Sub Command1_Click()
  387. 'Replace Spaces with Plus Signs In String Text
  388. '---------------------------------------------
  389. Dim i As Integer     'counting variable
  390. Dim temp As String   'text variable
  391. Let i = 1
  392. Let temp = Text1.Text
  393. Let Text1.Text = ""
  394. While i <= Len(temp)
  395. 'while the counter is less than the length of string
  396.  If Mid(temp, i, 1) = " " Then
  397.   'if the character is blank then
  398.   Mid(temp, i, 1) = "+"
  399.   'remove blank, add Null
  400.  End If
  401.  i = i + 1
  402.  'increase counter
  403. 'display new text
  404. Let Text1.Text = temp
  405. End Sub
  406. Private Sub Command10_Click()
  407. 'Count "O" in String
  408. amnt = AmtInStr(Text6.Text, "o")
  409. Msg = "In The String: " & Text6.Text
  410. Msg = Msg & Chr(13) & Chr(10)
  411. Msg = Msg & "The Letter 'O' Appeared: " & amnt & " Times"
  412. sstyle = vbInformation
  413. ttitle = "Letter Counter"
  414. MsgBox Msg, sstyle, ttitle
  415. End Sub
  416. Private Sub Command11_Click()
  417. amnt = AmtInStr(Text6.Text, "e")
  418. Msg = "In The String: " & Text6.Text
  419. Msg = Msg & Chr(13) & Chr(10)
  420. Msg = Msg & "The Letter 'T' Appeared: " & amnt & " Times"
  421. sstyle = vbInformation
  422. ttitle = "Letter Counter"
  423. MsgBox Msg, sstyle, ttitle
  424. End Sub
  425. Private Sub Command2_Click()
  426. Dim i As Integer     'counting variable
  427. Dim temp As String   'text variable
  428. Let i = 1
  429. Let temp = Text1.Text
  430. Let Text1.Text = ""
  431. While i <= Len(temp)
  432. 'while the counter is less than the length of string
  433.  If UCase(Mid(temp, i, 1)) = "A" Then
  434.   'if the character is blank then
  435.   Mid(temp, i, 1) = "B"
  436.   'remove blank, add Null
  437.  End If
  438.  i = i + 1
  439.  'increase counter
  440. 'display new text
  441. Let Text1.Text = temp
  442. End Sub
  443. Private Sub Command3_Click()
  444. 'Make All Text Uppercase
  445. '------------------------
  446. Text2.Text = UCase(Text2.Text)
  447. End Sub
  448. Private Sub Command4_Click()
  449. 'Make All Text Lowercase
  450. '-----------------------
  451. Text2.Text = LCase(Text2.Text)
  452. End Sub
  453. Private Sub Command5_Click()
  454. 'Reverse Strings
  455. '---------------
  456. Dim temp(1 To 100)
  457. 'create array to store characters
  458. Dim temp2 As String
  459. Dim t As Integer
  460. Let t = 1
  461. Let temp2 = Text3.Text
  462. While t <= Len(Text3.Text)
  463.  'load array with each individual character
  464.  temp(t) = Mid(Text3.Text, t, 1)
  465.  t = t + 1
  466. Text3.Text = ""
  467. Let t = 0
  468. While t <= Len(temp2) - 1
  469.  'reverse array information & display
  470.  Text3.Text = Text3.Text & temp((Len(temp2) - t))
  471.  t = t + 1
  472. End Sub
  473. Private Sub Command6_Click()
  474. 'Trim Leading Spaces
  475. Let Text4.Text = LTrim(Text4.Text)
  476. End Sub
  477. Private Sub Command7_Click()
  478. 'Trim trailing spaces
  479. Let Text4.Text = RTrim(Text4.Text)
  480. End Sub
  481. Private Sub Command8_Click()
  482. 'decrypt Data
  483. Text5.Text = CryptString2(Text5.Text, False)
  484. 'this is done in a Public Function.
  485. 'CryptString2 = Function Name
  486. 'text5.text = Data to be Encrypted
  487. 'True = Not Encrypted Yet
  488. 'False = Encrypted, must be decrypted
  489. End Sub
  490. Public Function CryptString2(txtString As String, EnCrypt As Boolean) As String
  491.        On Error GoTo errhandler
  492.        Dim x As Integer
  493.        Dim outString As String
  494.        Dim iLen As Integer
  495.        Dim sFirstSeed As String
  496.        Dim sSecondSeed As String
  497.        Dim iSeed As Integer
  498.        If EnCrypt Then
  499.            sFirstSeed = Left(txtString, 1)
  500.            sSecondSeed = Mid(txtString, 2, 1)
  501.            iSeed = (Asc(sFirstSeed) + Asc(sSecondSeed)) Mod 2
  502.            iLen = Len(txtString)
  503.            For x = 1 To iLen
  504.                outString = Chr((Asc(Mid$(txtString, x, 1)) Xor iSeed) + 2) & outString
  505.            Next
  506.            outString = Chr(Asc(sFirstSeed) * 2 + 3) & outString
  507.            outString = outString & Chr(Asc(sSecondSeed) * 2 - 3)
  508.        Else
  509.            sFirstSeed = Chr((Asc(Left(txtString, 1)) - 3) \ 2)
  510.            sSecondSeed = Chr((Asc(Right(txtString, 1)) + 3) \ 2)
  511.            iSeed = (Asc(sFirstSeed) + Asc(sSecondSeed)) Mod 2
  512.            iLen = Len(txtString) - 1
  513.            For x = 2 To iLen
  514.                outString = Chr((Asc(Mid$(txtString, x, 1)) Xor iSeed) - 2) & outString
  515.            Next
  516.        End If
  517.        CryptString2 = outString
  518.        Exit Function
  519. errhandler:
  520.        MsgBox "Error in CryptString" & vbCrLf & "Error: " & Err.Description & vbCrLf & "Number: " & Err.Number
  521.        CryptString2 = ""
  522.    End Function
  523. Private Sub Command9_Click()
  524. 'Encrypt Data
  525. Text5.Text = CryptString2(Text5.Text, True)
  526. 'this is done in a Public Function.
  527. 'CryptString2 = Function Name
  528. 'text5.text = Data to be Encrypted
  529. 'True = Not Encrypted Yet
  530. 'False = Encrypted, must be decrypted
  531. End Sub
  532. Public Function AmtInStr(String1 As String, String2 As String) As Long
  533. Dim Loop1 As Long, Amount As Integer
  534. Amount% = 0
  535. For Loop1& = 1 To Len(String1$)
  536.  If InStr(Loop1&, String1$, String2$) <> 0 Then
  537.   Loop1& = InStr(Loop1&, String1$, String2$)
  538.   Amount% = Amount% + 1
  539.  End If
  540.  DoEvents
  541.  Next Loop1&
  542.  AmtInStr& = Amount%
  543. End Function
  544. Private Sub Form_Unload(Cancel As Integer)
  545. 'Show Credits and End
  546. Msg = "Thank You For Trying Teco's 'FUN WITH TEXT' Examples"
  547. Msg = Msg & Chr(13) & Chr(10) & Chr(13) & Chr(10)
  548. Msg = Msg & "        Contact Teco:    teco@tecotown.com" & Chr(13) & Chr(10)
  549. Msg = Msg & "        Special Thanks To Jason Monroe and ANTI" & Chr(13) & Chr(10)
  550. sstyle = vbInformation
  551. ttitle = "Happy Coding!"
  552. MsgBox Msg, sstyle, ttitle
  553. End Sub
  554. Private Sub Label3_Click()
  555. End Sub
  556.